<?php

/**
 * Created by PhpStorm.
 * User: duanshuai
 * Date: 2018/3/23
 * Time: 下午11:26
 */

namespace app\index\model;
use think\Model;

class User extends Model
{
//根据传过来的用户名 判断是否注册
    public function isUserRegiste($count) {

       $user = self::getByCount($count);
//        var_dump($user);
        if ($user){
            return true;
        }else{
           return false;
        }




    }

    //注册或者更新个人信息  根据数组 过滤字段加入表
    public function registeOrUpdateCount($post){

        $count = $post['count'];
        $user = self::getByCount($count);
        if ($user){
            //已经有用户,更新用户信息
            unset($post['count']);


            //过滤空值  array_filter
            $user->save(array_filter($post),['count'=>$count]);
        }else {
            //新增信息

            $new = new User($post);
            $new->save();

        }


    }
    //查询个人信息
    public function findWhitCount($count){
        $user = self::getByCount($count);

        if ($user) {

            return ["status"=>0,'statusCode'=>'查询成功','data'=>$user->hidden(['password','token_id'])->toArray()];
        }else{
            return ["status"=>1,'statusCode'=>'没有此账号','data'=>[]];
        }
    }


}